// 模拟异步使用
import { createSlice } from '@reduxjs/toolkit'

const asyncListStore = createSlice({
    name: 'asyncList',
    initialState: {
        list: []
    },
    reducers: {
        setList(state, action) {
            state.list = action.payload;
        }
    }
})

// 解构方法-生成action方法(假装异步请求)
const { setList } = asyncListStore.actions
const fetchAsyncList = () => {
    return (dispatch) => {
        // 模拟异步请求
        // const ['是的', '学会了'] = await fetch('xxxx')
        dispatch(setList(['是的', '学会了']))
    }
}

// 导出action方法
export { fetchAsyncList };

// 获取reducer方法(将store模块)
const asyncListReducer = asyncListStore.reducer
export default asyncListReducer;
